﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZFS.Library;
using ZFS.Library.Helper;
using ZFS.Model;
using ZFSData.InterFace;

namespace ZFS.ServerBusiness
{
    public class WCF_DictionTypeManager : WCF_BaseManager<WCF_DictionTypeManager>, IDictionaryType
    {
        public tb_DictionaryType AddEntity(tb_DictionaryType entity)
        {
            var bytes = Server.AddEntityByDic(ZipTools.CompressionObject(entity));
            ServiceResponse response = ZipTools.DecompressionObject(bytes) as ServiceResponse;
            if (response.Success)
                return response.Results;
            else
                throw new Exception(response.Message);
        }

        public bool DeleteEntity(tb_DictionaryType entity)
        {
            var bytes = Server.DeleteEntityByDic(ZipTools.CompressionObject(entity));
            ServiceResponse response = ZipTools.DecompressionObject(bytes) as ServiceResponse;
            if (response.Success)
                return response.Results;
            else
                throw new Exception(response.Message);
        }

        public bool ExistEntity(tb_DictionaryType entity)
        {
            var bytes = Server.ExistEntityByDic(ZipTools.CompressionObject(entity));
            ServiceResponse response = ZipTools.DecompressionObject(bytes) as ServiceResponse;
            if (response.Success)
                return response.Results;
            else
                throw new Exception(response.Message);
        }

        public List<tb_DictionaryType> GetDictionaryTypes()
        {
            var bytes = Server.GetDictionarys();
            ServiceResponse response = ZipTools.DecompressionObject(bytes) as ServiceResponse;
            if (response.Success)
                return response.Results;
            else
                throw new Exception(response.Message);
        }

        public List<tb_DictionaryType> GetModels(tb_DictionaryType search)
        {
            var bytes = Server.GetModelsByDic(ZipTools.CompressionObject(search));
            ServiceResponse response = ZipTools.DecompressionObject(bytes) as ServiceResponse;
            if (response.Success)
                return response.Results;
            else
                throw new Exception(response.Message);
        }

        public List<tb_DictionaryType> GetPagingModels(int pageIndex, int pageSize, out int totalCount, tb_DictionaryType search, bool Asc = false)
        {
            var bytes = Server.GetPagingModelsByDic(pageIndex, pageSize, ZipTools.CompressionObject(search), Asc);
            ServiceResponse response = ZipTools.DecompressionObject(bytes) as ServiceResponse;
            if (response.Success)
            {
                totalCount = response.TotalCount;
                return response.Results;
            }
            else
                throw new Exception(response.Message);
        }

        public bool UpdateEntity(tb_DictionaryType entity)
        {
            byte[] bytes = Server.UpdateEntityByDic(ZipTools.CompressionObject(entity));
            ServiceResponse response = ZipTools.DecompressionObject(bytes) as ServiceResponse;
            if (response.Success)
                return response.Results;
            else
                throw new Exception(response.Message);
        }
    }
}
